package com.sbc.user.handler.chain;

import com.sbc.convention.exception.ClientException;
import com.sbc.user.enums.UserRegisterErrorCodeEnum;
import com.sbc.user.pojo.vo.UserRegisterReqVo;
import com.sbc.user.service.UserLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @description: 用户注册用户名唯一检验
 * @author: songbaicheng
 * @create: 2024-05-30 14:59
 **/
@Component
@RequiredArgsConstructor
public class UserRegisterHasUsernameChainHandler implements UserRegisterCreateChainFilter<UserRegisterReqVo> {

    private final UserLoginService userLoginService;

    @Override
    public void handler(UserRegisterReqVo requestParam) {
        if (userLoginService.hasUsername(requestParam.getUsername())) {
            throw new ClientException(UserRegisterErrorCodeEnum.USERNAME_REGISTERED);
        }
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
